package com.atguigu.yygh.cmn.controller;


import com.atguigu.yygh.cmn.service.DictService;
import com.atguigu.yygh.model.cmn.Dict;
import com.atguigu.yygh.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 组织架构表 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2025-03-13
 */
@RestController
@RequestMapping("/admin/cmn")
public class DictController {
    @Autowired
    private DictService dictService;

    @GetMapping("/dict/{parentId}")
    public R getDictListByParentId(@PathVariable("parentId") Long parentId) {
        //查询字典列表
        List<Dict> dictList = dictService.getDictListByParentId(parentId);
        return R.ok().data("list", dictList);
    }
    @GetMapping("/dict/byDictCode/{dictCode}")
    public R getDictListByDictCode(@PathVariable("dictCode") String dictCode) {
        //查询字典列表
        List<Dict> dictList = dictService.getDictListByDictCode(dictCode);
        return R.ok().data("list", dictList);
    }

    //导出字典数据
    @GetMapping("/dict/exportData")
    public R exportDict(HttpServletResponse response) throws Exception {
        //导出字典数据
        dictService.exportDict(response);
        return R.ok();
    }
    //导入字典数据
    @PostMapping("/dict/importData")
    public void importDict(MultipartFile file) throws Exception {
        //导入字典数据
        dictService.importDict(file);
    }
}

